package com.lzq.model.facade;

/**
 * @author : modify
 * @version : v1.0
 * @description :
 * @createTime : 2022/11/23 11:51
 * @updateUser : modify
 * @updateTime : 2022/11/23 11:51
 * @updateRemark :
 */
public class FacadeTest {
    public static void main(String[] args) {
        SmartAppliancesFacade smartAppliancesFacade = new SmartAppliancesFacade(new Light(), new Tv(), new AirCondition());
        smartAppliancesFacade.say("打开");
        smartAppliancesFacade.say("关闭");
    }
}

class Light {
    public void on() {
        System.out.println("open light");
    }

    public void off() {
        System.out.println("off light");
    }
}

class Tv {
    public void on() {
        System.out.println("open tv");
    }

    public void off() {
        System.out.println("off tv");
    }
}

class AirCondition {
    public void on() {
        System.out.println("open AirCondition");
    }

    public void off() {
        System.out.println("off AirCondition");
    }
}

class SmartAppliancesFacade {
    private Light light;
    private Tv tv;
    private AirCondition airCondition;
    private final static String OPEN = "打开";
    private final static String CLOSE = "关闭";

    public SmartAppliancesFacade(Light light, Tv tv, AirCondition airCondition) {
        this.light = light;
        this.tv = tv;
        this.airCondition = airCondition;
    }

    public void say(String msg) {
        if (OPEN.equals(msg)) {
            on();
        } else if (CLOSE.equals(msg)) {
            off();
        } else {
            System.out.println("说点人话");
        }
    }

    private void on() {
        light.on();
        tv.on();
        airCondition.on();
    }

    private void off() {
        light.off();
        tv.off();
        airCondition.off();
    }
}